package com.wei.api.controller;

import com.wei.biz.dto.form.GetBase64CodeForm;
import com.wei.biz.dto.form.GetSmsCodeForm;
import com.wei.biz.service.MemberLoginService;
import com.wei.common.dto.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequiredArgsConstructor
@Api(tags = "登录模块")
@RequestMapping("/login")
public class LoginController {
    private final MemberLoginService memberLoginService;

    @ApiOperation("获取客户端id")
    @GetMapping("/getClientId")
    public ApiResponse<String> getClientId() {
        String clientId = memberLoginService.getClientId();
        return ApiResponse.success(clientId);
    }

    @ApiOperation("获取图形验证码")
    @GetMapping("/getBase64Code")
    public ApiResponse<String> getBase64Code(@Validated @ModelAttribute GetBase64CodeForm form) {
            return ApiResponse.success(memberLoginService.getBase64Code(form));
    }

    @ApiOperation(value = "获取短信验证码")
    @GetMapping(value = "/sendSmsCode")
    public ApiResponse<Void> sendSmsCode(@Validated @ModelAttribute GetSmsCodeForm request) {
        memberLoginService.sendSmsCode(request);
        return ApiResponse.success();
    }
}
